<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script src="./jq-3.6.0.min.js"></script>
  <script>

    // 遍历操作 $.each(arr, function(item, index)) 
    var arr = ['hello', 'world', 'hi'];
    $.each(arr, function(index, item) {
      console.log(index, item);
    })

    var obj = {
      name: 'dili',
      age: 18,
      hobby: 'sleep',
    };
    $.each(obj, function(key, value) {
      console.log(key, value);
    })

    // 对象深拷贝
    var target = {};
    var obj1 = {
      name: 'dili1',
      age: '18',
      hobby: 'sleep',
    };
    var obj2 = {
      name: 'ming',
      age: 20,
    }
    $.extend(target, obj1, obj2);
    console.log(target); // {name: 'ming', age: 20, hobby: 'sleep'}

    // 筛选 过滤
    var arrG = [1, 2, 3, 4, 5];
    // 注意这里回调函数的参数 和each相反的
    $.grep(arrG, function (item, index) {
      if(item > 3) {
        console.log(item, index);
      }
    })

    // 遍历
    var arrM = ['hi', 'hello', 'haha'];
    $.map(arrM, function(item, index) {
      console.log(item, index);
    })

    var objM = {
      name: 'dili',
      age: 18,
      sex: 0
    };
    $.map(objM, function(value, key) {
      console.log(value, key);
    })

    // 查找成员item在数组arr中的下标
    var arr = [2, 'dili', 'reba'];
    console.log($.inArray('dili', arr));

    // 合并 
    var arr1 = [1, 2, 3];
    var arr2 = [2, 3, 4];
    console.log($.merge(arr1, arr2));

  </script>
</body>
</html>